﻿using System;

namespace Magellan.Routing
{
    public static class RouteCollectionExtensions
    {
        public static void Register(this RouteCollection routes, string name, string path, Func<IRouteHandler> routeHandler, object defaults = null, object constraints = null)
        {
            var route = new Route(name, path, routeHandler, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints));
            routes.Register(route);
        }

        public static void Register(this RouteCollection routes, string name, string path, IRouteHandler routeHandler, object defaults = null, object constraints = null)
        {
            var route = new Route(name, path, () => routeHandler, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints));
            routes.Register(route);
        }

        public static PathMatch MatchRouteToPath(this RouteCollection routes, object values)
        {
            return routes.MatchRouteToPath(new RouteValueDictionary(values));
        }
    }
}